package com.flyxiaozhu.erp.core.utils;

import org.apache.commons.lang.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

public class RequestUtils {
    @SuppressWarnings("unchecked")
    public static <T> Map<String, T> getParams(HttpServletRequest request) {
        Map<String, T> result = new HashMap<>();

        Map<String, String[]> ps = request.getParameterMap();
        for (String k : ps.keySet()) {
            String[] v = ps.get(k);
            if (v == null) {
                result.put(k, null);
            } else {
                result.put(k, (T) StringUtils.trim(v[0]));
            }
        }

        return result;
    }
}
